<?php

/**
 * uniBoard Admin output class
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-20 21:23:27 +0000 (Mon, 20 Sep 2010) $
 * $Revision: 64 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class class_admin_output extends class_templates_abstract{

	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	/**
	 * Style Images list
	 *
	 * @var array
	 */
	
	private $images			= array(
										'action_copy'			=> 'action_copy.png',
										'action_delete'			=> 'action_delete.png',
										'action_download'		=> 'action_download.png',
										'action_dropdown'		=> 'action_dropdown.png',
										'action_edit'			=> 'action_edit.png',
										'action_images'			=> 'action_images.png',
										'action_pass'			=> 'action_pass.png',
										'action_permissions'	=> 'action_permissions.png',
										'action_profile'		=> 'action_profile.png',
										'action_refresh'		=> 'action_refresh.png',
										'action_style_css'		=> 'action_style_css.png',
										'action_style_js'		=> 'action_style_js.png',
										'action_tool'			=> 'action_tool.png',
										'action_templates'		=> 'action_templates.png',
										'action_translate'		=> 'action_translate.png',
										'action_users'			=> 'action_users.png',
										
										'debug_time'			=> 'debug_time.png',
										'debug_db'				=> 'debug_db.png',
										'debug_memory'			=> 'debug_memory.png',
										
										'dialog_error'			=> 'dialog_error.png',
										'dialog_information'	=> 'dialog_information.png',
										
										'forum_type_0'			=> 'forum_type_0.png',
										'forum_type_1'			=> 'forum_type_1.png',
										'forum_type_2'			=> 'forum_type_2.png',
										
										'icon_acp_appearance'	=> 'icon_acp_appearance.png',
										'icon_acp_forum'		=> 'icon_acp_forum.png',
										'icon_acp_home'			=> 'icon_acp_home.png',
										'icon_acp_modules'		=> 'icon_acp_modules.png',
										'icon_acp_settings'		=> 'icon_acp_settings.png',
										'icon_acp_users'		=> 'icon_acp_users.png',
										'icon_login'			=> 'icon_login.png',
										'icon_nav_start'		=> 'icon_nav_start.png',
										'icon_redirect'			=> 'icon_redirect.png',
										'icon_settings_group'	=> 'icon_settings_group.png',
										
										'item_default'			=> 'item_default.png',
										'item_not_default'		=> 'item_not_default.png',
										
										'page_jump'				=> 'page_jump.png',
										'pip'					=> 'pip.png',
										
										'state_0'				=> 'state_0.png',
										'state_1'				=> 'state_1.png',
										
										'style_root'			=> 'style_root.png',
										'style_normal'			=> 'style_normal.png',
										'style_child'			=> 'style_child.png',
										
										'style_owner_0'			=> 'style_owner_0.png',
										'style_owner_1'			=> 'style_owner_1.png',
										'style_owner_2'			=> 'style_owner_2.png',
										
										'tree_s'				=> 'tree_s.gif',
										'tree_i'				=> 'tree_i.gif',
										'tree_t'				=> 'tree_t.gif',
										'tree_l'				=> 'tree_l.gif',
										
										'user_noimage'			=> 'user_noimage.png',
									);
		
	/**
	 * Global JS variables
	 *
	 * @var array
	 */
	
	public $js_vars			= array();

	/**
	 * Page specific JS Code
	 *
	 * @var string
	 */
	
	public $js_code			= '';

	/**
	 * Current admin action
	 *
	 * @var string
	 */
									
	public $action			= NULL;
	
	/**
	 * Current admin panel section
	 *
	 * @var string
	 */
	
	public $section			= NULL;
	
	/**
	 * Current admin page help
	 *
	 * @var string
	 */
	
	public $page_help		= NULL;
	
	/**
	 * Displayed error messages
	 *
	 * @var string
	 */
	
	public $msg_error		= NULL;
	
	/**
	 * Displayed non-error messages
	 *
	 * @var string
	 */
	
	public $msg_misc		= NULL;
																	
	// ------------------------------------------------------------------------

	/**
	 * Creates ACP display class
	 *
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Displays full admin page
	 *
	 * @param string $page_title
	 * @param string $page_action
	 * @param array $page_path
	 * @param string $page_content
	 */
	
	function draw( $page_title, $page_path, $page_content){
		
		// Draw starting Wrapper template
		$this -> startDrawing( $page_title);
		
		// Drawed path
		$path = '';
		
		// Reiterate items of path?
		if ( !empty( $page_path))
		{
			// Reiterate items
			foreach ( $page_path as $item_link => $item_label)
			{
				// Add item to path
				$path .= ' <span class="breadcrumb_spacer">&raquo;</span> ' . ( empty( $item_link) ? '<span class="breadcrumb_last">' : '<a href="' . $item_link . '">') . $item_label. ( empty( $item_link) ? '</span>' : '</a>');
			}	
		}
		
		// Drawed blocks
		$blocks = '';
		
		// If we are not in forum home and modules page, load blocks from map
		if ( $this -> section != 'home' && $this -> section != 'modules')
		{
			// Start try-catch
			try
			{
				// Blocks file exists?
				if ( !file_exists( ADMIN_BLOCKS_MAP_PATH))
				{
					throw new exc_critical( 'FILE', $this -> appCore -> lang['acp_map_blocks_not_found'], ADMIN_BLOCKS_MAP_PATH . $this -> appCore -> lang['file_does_not_exists']);
				}
				
				// Include blocks list
				require_once( ADMIN_BLOCKS_MAP_PATH);
				
				// Map file correct?
				if ( !isset( $blocks_map) || !is_array( $blocks_map) || !isset( $blocks_map[$this -> section]))
				{
					throw new exc_critical( 'FILE', $this -> appCore -> lang['acp_map_blocks_incorrect'], ADMIN_BLOCKS_MAP_PATH);
				}
				
				// Reiterate blocks for our section
				foreach ( $blocks_map[$this -> section] as $block_title => $block_links)
				{
					// Block content
					$block_content = '';
					
					// Draw links
					foreach ( $block_links as $item_link => $item_title)
					{
						$block_content .= '<a href="' . $item_link . '">' . $item_title . '</a>';
					}
					
					// Draw block
					$blocks .= $this -> sideBlock( $block_title, $block_content);
				}
				
				// Trash out
				unset( $block_content);
			}
			catch ( exc_critical $exception)
			{
				// Kill software
				exit( $exception);	
			}
		}
		else if ( $this -> section == 'modules')
		{
			// Load blocks from DB
		}
		
		// Open page with template
		echo $this -> pageStart( $page_title, $path, $blocks);
		
		// Draw page content
		echo $page_content;
		
		// Draw closing Wrapper template
		echo $this -> pageEnd();
		echo $this -> wrapperEnd();
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Displays simple admin page
	 *
	 * @param string $page_title
	 * @param string $page_content
	 */
	
	function drawSimple( $page_title, $page_content){
		
		// Draw starting Wrapper template
		$this -> startDrawing( $page_title);
		
		// Open page with template
		echo $this -> pageSimpleStart();
		
		// Draw page content
		echo $page_content;
		
		// Draw closing templates
		echo $this -> pageSimpleEnd();
		echo $this -> wrapperEnd();
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Sends headers and draws opening wrapper HTML
	 *
	 * @param string $page_title
	 */
	
	function startDrawing( $page_title){
		
		// Send no-cache headers?
		if ( $this -> appCore -> conf['server_send_nocache'])
		{
			//force no cache
			header( 'Cache-Control: no-cache, must-revalidate');
			header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT');
		}
		
		// Content type header
		header( 'Content-Type: text/html;charset=utf-8');	
		
		// JS variables
		$js_vars = '';
		
		// Put vars from core class
		if ( !empty( $this -> js_vars))
		{
			// Reiterate vars
			foreach ( $this -> js_vars as $var => $val)
			{
				// Add it to ready items
				$js_vars .= '		var ' . $var . ' = "' . htmlspecialchars( $val, 1) . '";
';
			}
		}
		
		// Draw wrapper start template
		echo $this -> wrapperStart( htmlspecialchars( isset( $page_title[0]) ? PRODUCT_NAME . ': ' . $page_title : PRODUCT_NAME), $js_vars);
		
	}
		
	// ------------------------------------------------------------------------

	/**
	 * Draws redirect page
	 *
	 * @param string $redirect_link
	 * @param string $redirect_message
	 */
	
	function drawRedirect( $redirect_link = '', $redirect_message = ''){
				
		// Send redirect headers
		$this -> appCore -> setRedirect( $redirect_link);
		
		// Draw redirect page?
		if ( !$this -> appCore -> conf['redirections_instant'])
		{
			// Send basic headers
			$this -> startDrawing( $this -> appCore -> lang['redirect_title']);
			
			// Open page with template
			echo $this -> pageSimpleStart();
			
			// Draw template
			echo '		<h2>' . $this -> drawImage( 'icon_redirect') . ' ' . $this -> appCore -> lang['redirect_title'] . '</h2>
			<p>' . ( isset( $redirect_message[0]) ? $redirect_message : $this -> appCore -> lang['redirect_default_message']) . '</p>
			<p><a href="' . $redirect_link . '">' . $this -> appCore -> lang['redirect_link'] . '</a></p>';
			
			// Draw closing templates
			echo $this -> pageSimpleEnd();
			echo $this -> wrapperEnd();
		}
		
	}

	// ------------------------------------------------------------------------

	/**
	 * Draws error message
	 *
	 * @param string $text
	 * @param string $title
	 */
	
	function error( $text, $title = ''){
		
		$this -> msg_error .= '<div class="event_error">
						<h2>' . $this -> drawImage( 'dialog_error', $this -> appCore -> lang['error']) . ' ' . ( isset( $title[0]) ? $title : $this -> appCore -> lang['error']). '</h2>
						<p>' . $text . '</p>
					</div>';
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Draws misc message
	 *
	 * @param string $text
	 * @param string $title
	 */
	
	function message( $text, $title = ''){

		$this -> msg_misc .= '<div class="event_ok">
						<h2>' . $this -> drawImage( 'dialog_information', $this -> appCore -> lang['information']) . ' ' . ( isset( $title[0]) ? $title : $this -> appCore -> lang['information']). '</h2>
						<p>' . $text . '</p>
					</div>';
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Runs and draws debugger
	 *
	 * @return string
	 */
	
	function drawDebug(){
		
		// Draw debugger?
		if ( $this -> appCore -> conf['board_debug_level'])
		{
			// Run action
			$debugger = new action_debug( $this -> appCore);
			
			// Return generated code
			return $debugger -> draw();
		}
		else
		{
			// Return Null
			return NULL;
		}
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Displays style image
	 *
	 * @param string $image_key
	 * @param string $image_alt
	 * @param integer $image_width
	 * @param integer $image_height
	 * @return string
	 */
	
	function drawImage( $image_key, $image_alt = '', $image_width = 0, $image_height = 0){

		//image exists?
		if ( isset( $this -> images[$image_key]))
		{
			// Use alternate string?
			if ( !empty( $image_alt))
			{
				// Fix html chars
				$image_alt = htmlspecialchars( $image_alt);
				
				// Return html tag string
				return '<img src="' . ADMIN_PATH . $this -> images[$image_key] . '" alt="' . $image_alt . '" title="' . $image_alt . '" />';
			}
			else
			{
				// Return html tag string
				return '<img src="' . ADMIN_PATH . $this -> images[$image_key] . '" alt="" title="" />';
			}
		}
		else
		{
			// Return NULL string
			return '';
		}
		
	}
	
	// ------------------------------------------------------------------------
	// COMPILED TEMPLATES START HERE	
	// ------------------------------------------------------------------------
	
	/**
	 * Opening wrapper template
	 *
	 * @param string $page_title
	 * @param string $js_vars
	 * @return string
	 */
	
	function wrapperStart( $page_title, $js_vars = ''){
		
		return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="' . ADMIN_CSS_PATH . '" type="text/css" />
<title>' . $page_title . '</title>
<script type="text/javascript" src="' . JS_FRAMEWORK_PATH . '"></script>
<script type="text/javascript" src="' . JS_BOARD_PATH . '"></script>
<script type="text/javascript" src="' . ADMIN_JAVA_PATH . '"></script>' . ( isset( $js_vars[0]) || isset( $this -> js_code[0]) ? '
<script type="text/javascript">	
	//<![CDATA[
	
' . ( isset( $js_vars[0]) ? $js_vars : '') . '
' . $this -> js_code . '

	//]]>
</script>' : '') . '
<link rel="shortcut icon" href="' . DEFAULT_FAVICON_PATH . '" />
</head>
<body>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Closing wrapper template
	 *
	 * @return string
	 */
	
	function wrapperEnd(){
		
		return '</body>
</html>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Opening page template
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function pageStart( $page_title, $path, $blocks){
		
		$tpl_html = '<div id="wrapper">
	<div id="page_head">
		<h1>' . PRODUCT_NAME . ' <span id="product_name">' . $this -> appCore -> lang['acp_title'] . '</span></h1>
		<div id="page_head_menu">
			<b>' . $this -> appCore -> lang['acp_welcome'] . ' ' . htmlspecialchars( $this -> appCore -> user['name']). '!</b> <a href="' . $this -> appCore -> link() . '">' . $this -> appCore -> lang['acp_user_to_forum'] . '</a> | <a href="' . $this -> appCore -> adminLink( 'act=login&do=logout', true) . '">' . $this -> appCore -> lang['acp_user_logout'] . '</a>
		</div>
	</div>
	<div id="page_body">
		<div id="page_nav">
			<a href="' . $this -> appCore -> adminLink( 'sect=home') . '"' . ( $this -> section == 'home' ? ' id="nav_active"' : '') . '>' . $this -> drawImage( 'icon_acp_home') . ' ' . $this -> appCore -> lang['acp_section_home'] . '</a>
			<a href="' . $this -> appCore -> adminLink( 'sect=settings') . '"' . ( $this -> section == 'settings' ? ' id="nav_active"' : '') . '>' . $this -> drawImage( 'icon_acp_settings') . ' ' . $this -> appCore -> lang['acp_section_settings'] . '</a>
			<a href="' . $this -> appCore -> adminLink( 'sect=users') . '"' . ( $this -> section == 'users' ? ' id="nav_active"' : '') . '>' . $this -> drawImage( 'icon_acp_users') . ' ' . $this -> appCore -> lang['acp_section_users'] . '</a>
			<a href="' . $this -> appCore -> adminLink( 'sect=forums') . '"' . ( $this -> section == 'forums' ? ' id="nav_active"' : '') . '>' . $this -> drawImage( 'icon_acp_forum') . ' ' . $this -> appCore -> lang['acp_section_forums'] . '</a>
			<a href="' . $this -> appCore -> adminLink( 'sect=modules') . '"' . ( $this -> section == 'modules' ? ' id="nav_active"' : '') . '>' . $this -> drawImage( 'icon_acp_modules') . ' ' . $this -> appCore -> lang['acp_section_modules'] . '</a>
			<a href="' . $this -> appCore -> adminLink( 'sect=look') . '"' . ( $this -> section == 'look' ? ' id="nav_active"' : '') . '>' . $this -> drawImage( 'icon_acp_appearance') . ' ' . $this -> appCore -> lang['acp_section_look'] . '</a>
		</div>
		<div id="page_content">
			<div id="breadcrumbs">
				' . $this -> drawImage( 'icon_nav_start') . ' <a href="' . $this -> appCore -> adminLink() . '">' . $this -> appCore -> lang['acp_nav_home'] . '</a>' . $path . '
			</div>';
		
		// Draw blocks?
		if ( empty( $blocks))
		{
			$tpl_html .= '
			<div id="layout_content_alone">';
		}
		else
		{
			$tpl_html .= '
			<div id="layout_blocks">
				' . $blocks . '
			</div>
			<div id="layout_content">';
		}
		
		$tpl_html .= '
				<h2 id="page_title">' . $page_title . '</h2>
		';
		
		// Draw page help
		if ( !empty( $this -> page_help))
		{
			$tpl_html .= '
			<p>
				' . $this -> page_help . '
			</p>';
		}
		
		// Draw error messages
		if ( !empty( $this -> msg_error))
		{
			$tpl_html .= '<div class="events_error_container">' . $this -> msg_error . '</div>';
		}
		
		// Draw miscenary messages
		if ( !empty( $this -> msg_misc))
		{
			$tpl_html .= '<div class="events_ok_container">' . $this -> msg_misc . '</div>';
		}
		
		// Return ready template
		return $tpl_html;
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Opening page template
	 *
	 * @return string
	 */
	
	function pageEnd(){
		
		return '
			</div>
		</div>
	</div>
	<div id="footer">' . ( $this -> appCore -> conf['board_debug_level'] > 0 ? '
		<div id="debug_summary">' . $this -> drawImage( 'debug_time', $this -> appCore -> lang['debug_time']) . ' ' . round( microtime( true) - $this -> appCore -> gen_clock, 5) . ' s ' . $this -> drawImage( 'debug_db', $this -> appCore -> lang['debug_db']) . ' ' . $this -> appCore -> db_queries . ' ' . $this -> drawImage( 'debug_memory', $this -> appCore -> lang['debug_memory']) . ' ' . class_strings::countSize( memory_get_usage( true)) . '</div>' : '') . '
		<div class="right_float fixed_height">powered by <a href="http://uniboard-project.org">' . PRODUCT_NAME . '</a> &copy; ' . gmdate( 'Y') . ' by Rafał Pitoń</div>
	</div>
</div>' . $this -> drawDebug() . $this -> appCore -> runTasks();
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Opening simple page template
	 *
	 * @return string
	 */
	
	function pageSimpleStart(){
		
		return '<div id="wrapper_simple">
	<div id="page_head">
		<h1>' . PRODUCT_NAME . ' <span id="product_name">' . $this -> appCore -> lang['acp_title'] . '</span></h1>
	</div>
	<div id="page_body_simple">';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Closing simple page template
	 *
	 * @param string $tasks
	 * @return string
	 */
	
	function pageSimpleEnd(){
		
		return '</div>
	<div id="footer">' . ( $this -> appCore -> conf['board_debug_level'] > 0 ? '
		<div id="debug_summary">' . $this -> drawImage( 'debug_time', $this -> appCore -> lang['debug_time']) . ' ' . round( microtime( true) - $this -> appCore -> gen_clock, 5) . ' s ' . $this -> drawImage( 'debug_db', $this -> appCore -> lang['debug_db']) . ' ' . $this -> appCore -> db_queries . ' ' . $this -> drawImage( 'debug_memory', $this -> appCore -> lang['debug_memory']) . ' ' . class_strings::countSize( memory_get_usage( true)) . '</div>' : '') . '
		<div class="right_float fixed_height">powered by <a href="http://uniboard-project.org">' . PRODUCT_NAME . '</a> &copy; ' . gmdate( 'Y') . ' by Rafał Pitoń</div>
	</div>
</div>' . $this -> drawDebug() . $this -> appCore -> runTasks();
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Side block template
	 * 
	 * @param string $block_title
	 * @param string $block_content
	 * @return string
	 */
	
	function sideBlock( $block_title, $block_content){
		
		return '				<h2>' . $block_title . '</h2>
				<div class="side_block">
					' . $block_content . '
				</div>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * ACP login template
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function loginForm( $tpl_vars = array()){
		
		$tpl_html = '<h2>' . $this -> drawImage( 'icon_login', $this -> appCore -> lang['login_title']) . ' '. $this -> appCore -> lang['login_msg_acp'] . '</h2>';
		
		if ( !empty( $tpl_vars['login_message']))
		{
			$tpl_html .= '
		<div class="event_error">
			<h2>' . $this -> appCore -> lang['login_error'] . '</h2>
			' . $tpl_vars['login_message'] . '
		</div>';
		}
				
		return $tpl_html . '
		<form action="' . $this -> appCore -> adminLink( 'act=login&do=auth') . '" method="POST">
			<div id="login_fieldset">
				<div class="login_field">
					<div><label for="user_login">' . $this -> appCore -> lang['login_form_login'] . '</label></div>
					<input id="user_login" name="user_login" type="text" class="form_text " value="' . ( isset( $tpl_vars['user_login']) ? htmlspecialchars( $tpl_vars['user_login']) : '') . '"/>
				</div>
				<div class="login_field">
					<div><label for="user_password">' . $this -> appCore -> lang['login_form_password'] . '</label></div>
					<input id="user_password" name="user_password" type="password" class="form_text" value=""/>
				</div>
			</div>
			<div class="fixed_height">
				<div class="left_float line_height"><a href="' . $this -> appCore -> link() . '">' . $this -> appCore -> lang['acp_logins_forums'] . '</a></div>
				<input name="" type="submit" value="' . $this -> appCore -> lang['login_form_button'] . '" class="form_button_dark right_float"/>
			</div>
		</form>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Start Form
	 *
	 * @param string $action
	 * @param bool $file_transfer
	 * @return string
	 */
	
	function openForm( $action, $form_name = '', $file_transfer = false, $form_method = 'POST'){
		
		return '<form id="' . $form_name . '" name="' . $form_name . '" action="' . $action . '" method="' . $form_method . '" ' . ( $file_transfer ? 'enctype="multipart/form-data"' : '') . '>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Close Form
	 *
	 * @return string
	 */
	
	function closeForm(){
		
		return '</form>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Start ACP block with table
	 *
	 * @param string $title
	 * @param string $description
	 * @return string
	 */
	
	function openTableBlock( $title = '', $description = ''){
		
		return ( !empty( $title) ? '<h2 class="block_title">' . $title . '</h2>' : '') . ( empty( $description) ? '' : '<p class="block_description">' . $description . '</p>') . '<div class="table_border">';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Close ACP block with table
	 *
	 * @return string
	 */
	
	function closeTableBlock(){
		
		return '</div>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Draws table header
	 *
	 * @param mixed $content
	 * @return string
	 */
	
	function tableHeader( $content = ''){

		// Any cells in row?
		if ( !empty( $content))
		{
			// Is content an array?
			if ( is_array( $content))
			{
				// Drawn rows
				$drawed_rows = '';
				
				// Reiterate content
				foreach ( $content as $row_item)
				{
					// Row item is array?
					if ( is_array( $row_item))
					{
						$drawed_rows .= '<div class="cell ' . $row_item[0] . '">
							' . $row_item[1] . '
						</div>';
					}
				}
				
				// Draw row with text
				return '<div class="table_head">
						' . $drawed_rows . '
					</div>';
			}
			else
			{
				// Draw row with text
				return '<div class="table_head">
						' . $content . '
					</div>';
			}
		}
		else
		{
			// Return empty string
			return '';
		}
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Draws table spacer
	 *
	 * @param mixed $content
	 * @return string
	 */
	
	function tableSpacer( $content = ''){

		// Any cells in row?
		if ( !empty( $content))
		{
			// Is content an array?
			if ( is_array( $content))
			{
				// Drawn rows
				$drawed_rows = '';
				
				// Reiterate content
				foreach ( $content as $row_item)
				{
					// Row item is array?
					if ( is_array( $row_item))
					{
						$drawed_rows .= '<div class="cell ' . $row_item[0] . '">
							' . $row_item[1] . '
						</div>';
					}
				}
				
				// Draw row with text
				return '<div class="table_space">
						' . $drawed_rows . '
					</div>';
			}
			else
			{
				// Draw row with text
				return '<div class="table_space">
						' . $content . '
					</div>';
			}
		}
		else
		{
			// Return empty string
			return '';
		}
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Draws table row
	 *
	 * @param string $content
	 * @param string $class
	 * @return string
	 */
	
	function tableRow( $content = '', $class = ''){

		// Any cells in row?
		if ( !empty( $content))
		{
			// Draw row with text
			$tpl_html = '<div class="row_' . $this -> zebra( 'table_row', '1|0') . ' ' . $class .'">
					<div class="row_padding">' . $content . '</div>
				</div>';
			
			// Update zebras	
			$this -> updateZebras( 'table_row');
			
			// Return row template
			return $tpl_html;
		}
		else
		{
			// Return empty string
			return '';
		}
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Start ACP block with form
	 *
	 * @param string $title
	 * @param string $description
	 * @return string
	 */
	
	function openFormBlock( $title = '', $description = ''){
		
		return ( !empty( $title) ? '<h2 class="block_title">' . $title . '</h2>' : '') . ( empty( $description) ? '' : '<p class="block_description">' . $description . '</p>') . '<div class="block_border">';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Close ACP block with form
	 *
	 * @return string
	 */
	
	function closeFormBlock(){
		
		return '</div>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Form item
	 *
	 * @param string $title
	 * @param string $input
	 * @param string $description
	 * @return string
	 */
	
	function formItem( $title, $input = '', $description = ''){

		$tpl_html = '<div class="field_body field_color_' . ( $this -> zebra( 'form_item', '0|1')) . '">
					<div class="field_label">
						<b>' . $title. '</b>
					</div>
					<div class="field_input">
						' . $input . ( empty( $description) ? '' : '
						<div class="item_description">
							' . $description . '
						</div>') . '
					</div>
				</div>';
		
		$this -> updateZebras( 'form_item');
		return $tpl_html;
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Submit button inside fields block
	 *
	 * @param string $label
	 * @param string $add
	 * @return string
	 */
	
	function submitButton( $label = '', $add = '', $class = ''){
		
		return '<div class="submit_button center">
						<input name="" type="submit" value="' . ( empty( $label) ? $this -> appCore -> lang['send'] : htmlspecialchars( $label)) . '" class="form_button_dark ' . $class . '"/>' . ( isset( $add[0]) ? ' ' . $add : '') . '
					</div>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Submit button outside fields block
	 *
	 * @param string $label
	 * @return string
	 */
	
	function submitButtonAlone( $label = ''){
		
		return '<div class="submit_button_alone">
						<input name="" type="submit" value="' . ( empty( $label) ? $this -> appCore -> lang['send'] : htmlspecialchars( $label)) . '" class="form_button_dark"/>
					</div>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Submit row
	 *
	 * @param string $content
	 * @return string
	 */
	
	function submitRow( $content = ''){
		
		return '<div class="submit_button fix_height">
						' . $content . '
					</div>';
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Draws tools popup
	 *
	 * @param array $options
	 * @return string
	 */
	
	function toolsPopup( $options = ''){

		// Any options?
		if ( empty( $options))
		{
			// No options received, display nothing
			return NULL;
		}
		else
		{
			// Return ready template
			return '<div class="popup_container"><a href="#" class="popup_button"><div>' . $this -> appCore -> lang['options_popup_button'] . '</div></a><div class="popup_window">' . $options . '</div></div>';
		}
		
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Draws parsing options
	 *
	 * @return string
	 */
	
	function parsingOps( $field_name, $bbcode, $smileys, $links, $bbcode_parse = true, $smileys_parse = true, $links_parse = true){
		
		return '<div class="form_text_area_options">
	' . ( $bbcode ? '<div>' . $this -> appCore -> drawCheckbox( $field_name . '_bbcode', $bbcode_parse) . ' <label for="' . $field_name . '_bbcode">' . $this -> appCore -> lang['editor_op_bbcode'] . '</label></div>' : '') . '
	' . ( $smileys ? '<div>' . $this -> appCore -> drawCheckbox( $field_name . '_smileys', $smileys_parse) . ' <label for="' . $field_name . '_smileys">' . $this -> appCore -> lang['editor_op_smileys'] . '</label></div>' : '') . '
	' . ( $links ? '<div>' . $this -> appCore -> drawCheckbox( $field_name . '_links', $links_parse) . ' <label for="' . $field_name . '_links">' . $this -> appCore -> lang['editor_op_links'] . '</label></div>' : '') . '
</div>';
		
	}
	
}